package com.gufe.service.admin.impl.mmp;

import com.gufe.dto.MilitaryShowDTO;
import com.gufe.dto.prereserve.MilitaryInfoDTO;
import com.gufe.entity.MilitaryInfo;
import com.gufe.entity.MilitaryShow;
import com.gufe.mapper.admin.mmp.MilitaryTrainMapper;
import com.gufe.service.admin.mmp.MilitaryTrainService;
import com.gufe.vo.MilitaryShowVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MilitaryTrainServiceImpl implements MilitaryTrainService {
    @Autowired
    private MilitaryTrainMapper militaryTrainMapper;

    // 获取军事训练展示相关信息
    public List<MilitaryShowVO> getTrainInfo() {
        return militaryTrainMapper.getTrainInfo();
    }

    // 新建军训展示信息
    public void addTrainInfo(MilitaryShowDTO militaryShowDTO) {
        MilitaryShow militaryShow = new MilitaryShow();
        BeanUtils.copyProperties(militaryShowDTO,militaryShow);
        militaryTrainMapper.addTrainInfo(militaryShow);
    }

    // 更新军训展示信息
    public void updateTrainInfo(MilitaryShowDTO militaryShowDTO) {
        MilitaryShow militaryShow = new MilitaryShow();
        BeanUtils.copyProperties(militaryShowDTO,militaryShow);
        militaryTrainMapper.updateTrainInfo(militaryShow);
    }

    // 根据ID删除军事训练展示信息
    public void deleteTrainInfo(Integer id) {
        militaryTrainMapper.deleteTrainInfo(id);
    }


    // 根据ID获取军事训练展示信息
    public MilitaryShowVO getTrainInfoById(Integer id) {

        MilitaryShow militaryShow =  militaryTrainMapper.getInfoById(id);
        return MilitaryShowVO.builder()
                .id(militaryShow.getId())
                .title(militaryShow.getTitle())
                .content(militaryShow.getContent())
                .imgUrl(militaryShow.getImgUrl())
                .videoUrl(militaryShow.getVideoUrl())
                .updatedAt(militaryShow.getUpdatedAt())
                .build();
    }
}
